package com.silky.common.utils;


import com.silky.common.constant.IConstant;

import java.util.HashMap;
import java.util.Map;

/**
 * 解释参数工具类
 */
public class ParameterUtils {
    public static Map<String,String> makeParameterMap(String[] args) {
        Map<String,String> parameterMap = new HashMap<>();
        for (int i = 0; i < args.length; i++) {
            if (args[i].equalsIgnoreCase(IConstant.DATA_SOURCE_YML)) {
                if(i< args.length) {
                    parameterMap.put(IConstant.DATA_SOURCE_YML, args[i+1]);
                }else{
                    parameterMap.put(IConstant.DATA_SOURCE_YML, "");
                }
            }else if (args[i].equalsIgnoreCase(IConstant.TASK_YML)) {
                if(i< args.length) {
                    parameterMap.put(IConstant.TASK_YML, args[i+1]);
                }else{
                    parameterMap.put(IConstant.TASK_YML, "");
                }
            }
        }
        return parameterMap;
    }

    public static String getParameter(String[] args, String parameterName) {
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals(parameterName)) {
                return args[i + 1];
            }
        }
        return null;
    }
}
